/*
var initCurrentUsers = function() {
	getCurrentUsers();
}
*/

function getCurrentUsers(gmap) {
	
	  var image = new google.maps.MarkerImage('http://code.google.com/intl/zh-TW/apis/maps/documentation/javascript/examples/images/beachflag.png',
		      // This marker is 20 pixels wide by 32 pixels tall.
		      new google.maps.Size(20, 32),
		      // The origin for this image is 0,0.
		      new google.maps.Point(0,0),
		      // The anchor for this image is the base of the flagpole at 0,32.
		      new google.maps.Point(0, 32));
	  var shadow = new google.maps.MarkerImage('http://code.google.com/intl/zh-TW/apis/maps/documentation/javascript/examples/images/beachflag_shadow.png',
		      // The shadow image is larger in the horizontal dimension
		      // while the position and offset are the same as for the main image.
		      new google.maps.Size(37, 32),
		      new google.maps.Point(0,0),
		      new google.maps.Point(0, 32));
		      // Shapes define the clickable region of the icon.
		      // The type defines an HTML <area> element 'poly' which
		      // traces out a polygon as a series of X,Y points. The final
		      // coordinate closes the poly by connecting to the first
		      // coordinate.
	  var shape = {
			  coord: [1, 1, 1, 20, 18, 20, 18 , 1],
			  type: 'poly'
	  };


	  var infoWindow = new google.maps.InfoWindow;
		    function onMarkerClick() {
				var marker = this;
				var latLng = marker.getPosition();
				
				infoWindow.setContent('<b>['+marker.getTitle()+']目前位於  :</b></br>' +
					latLng.lat() + ', ' + latLng.lng() +'<br/>');
				
				infoWindow.open(gmap, marker);
				// gmap.setCenter(marker.getPosition());

		    };
		    google.maps.event.addListener(gmap, 'click', function() {
		      infoWindow.close();
	 });
	
	
	// indicate loading
	ajaxRequest('GET', encodeURI('CurrentUser'), {
		'Accept': 'application/json'
	}, null, function(status, headers, body) { // success callback
		// update html

		var current = eval('(' + body + ')');

		for(var i = 0; i < current.length; i++) {

			// alert(current[i].username+" "+current[i].coordinate.longitude+" "+current[i].coordinate.latitude);

			    var myLatLng = new google.maps.LatLng(current[i].coordinate.longitude, current[i].coordinate.latitude);
			    var marker = new google.maps.Marker({
			        position: myLatLng,
			        map: gmap,
			        shadow: shadow,
			        icon: image,
			        shape: shape,
			        title: current[i].username,

			        zIndex: 1
			    });
				//attachSecretMessage(marker, i);
			     google.maps.event.addListener(marker, 'click', onMarkerClick);
			     
		}

        	}, function(status, headers, body) {  // error callback
		alert('error: ' + status);
	}, null); // run callbacks in global scope  */

}

